package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// Merchant 商户
type Merchant struct {
	ID           string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	PID          string `json:"pid,omitempty" gorm:"column:pid;type:int;size:64;comment:上级商户id"`
	MerchantPath string `json:"merchant_path" gorm:"column:merchant_path;type:string;size:200;index:merchant_path;default:null;comment:商户开通路径,如>1>2"`
	Name         string `json:"name,omitempty" gorm:"column:name;type:string;size:40;index:name,unique;comment:商户名称"`
	ContactUser  string `json:"contact_user,omitempty" gorm:"column:contact_user;type:string;size:40;comment:联系人"`
	ContactPhone string `json:"contact_phone,omitempty" gorm:"column:contact_phone;type:string;size:40;comment:联系电话"`
	ContactAddr  string `json:"contact_addr,omitempty" gorm:"column:contact_addr;type:string;size:150;comment:联系地址"`
	AdminUserID  string `json:"admin_user_id,omitempty" gorm:"column:admin_user_id;type:int;size:64;default:null;comment:管理员id"`
	APIToken     string `json:"api_token" gorm:"column:api_token;type:string;size:32;index:api_token,unique;default:null;comment:接口token"`
	CreatedAt    int64  `json:"created_at,omitempty" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	UpdatedAt    int64  `json:"updated_at,omitempty" gorm:"autoUpdateTime;column:updated_at;type:int;size:64;comment:更新时间"`
	DeletedAt    int64  `json:"deleted_at,omitempty" gorm:"column:deleted_at;type:int;size:64;default:0;comment:删除时间"`
}

// TableName 表名称
func (m Merchant) TableName() string {
	return "merchant"
}

// BeforeCreate 自增id
func (m *Merchant) BeforeCreate(tx *gorm.DB) (err error) {
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &Merchant{})
}
